/**
 * 
 */
package cdms.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;


/**
 * <p> Project name:CDMS </p>
 * <p> Class name:TimeSendingTag </p>
 * @author "JiHongru"
 * @version
 * @date 2019年11月25日下午6:42:46
 * @description
 *
 */
public class TimeSendingTag extends SimpleTagSupport {
	
	/**
	 * receiveTime
	 */
	private Date date;	
	
	/**
	 * doTag
	 * @throws JspException, IOException
	 */
	public void doTag() throws JspException, IOException  {
		getJspContext().getOut().write(getTime());
	}
	
	/**
	 * get the time different between now and receivetime
	 * 
	 * @return String
	 *
	 */
	public String getTime() {
		Date now = new Date();
		String time = "";
		long day = (long) ((now.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
		long hour = (long) ((now.getTime() - date.getTime() - day*24*60*60*1000) / (1000 * 60 * 60));
		long min = (long) ((now.getTime() - date.getTime() - day*24*60*60*1000 - hour*60*60*1000) / (1000 * 60));
		long sec = (long) ((now.getTime() - date.getTime() - day*24*60*60*1000 - hour*60*60*1000 - min*60*1000) / (1000));
		
		if (day != 0) {
			time = day + "天" + hour + "时" + min + "分" + sec + "秒";
		}else if (hour != 0) {
			time = hour + "时" + min + "分" + sec + "秒";
		}else {
			time = min + "分" + sec + "秒";
		}
		return time;
	}

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}
}
